package com.ciaojian.worker.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.paths.RelativePathProvider;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

/**
 * @author Atlakyn
 */
@Configuration
@EnableSwagger2
public class SwaggerDocConfig {
    @Resource
    private ServletContext servletContext;

    @Bean
    public Docket getDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("发型师端")
                .apiInfo(swaggerDemoApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ciaojian.worker.controller"))
                .build()
                .pathProvider(new RelativePathProvider(servletContext){
                    @Override
                    public String getApplicationBasePath() {
                        return "/worker";
                    }
                })
                ;
    }

    @Bean
    public ApiInfo swaggerDemoApiInfo() {
        return new ApiInfoBuilder()
                .contact(new Contact("Atlakyn", "", ""))
                .title("发型师端接口文档")
                .description("发型师端小程序")
                .version("1.0.0")
                .build();
    }

    @Bean
    public ApiInfo swaggerWorkerApiInfo() {
        return new ApiInfoBuilder()
                .contact(new Contact("Atlakyn2", "", ""))
                .title("发型师端接口文档2")
                .description("发型师端小程序2")
                .version("1.0.1")
                .build();
    }

}
